package lucene.server.common.utils;

import java.lang.reflect.Field;

import lucene.server.common.model.Table;


public class ReflectUtil {
    public static Object getFieldValue(Object obj, String fieldName) throws NoSuchFieldException, IllegalAccessException {
        Field field = obj.getClass().getDeclaredField(fieldName);
        field.setAccessible(true); // 如果字段是private的，则需要这行代码
        return field.get(obj);
    }
    public static void setFieldValue(Object obj, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException {
        Field field = obj.getClass().getDeclaredField(fieldName);
        field.setAccessible(true); // 如果字段是private的，则需要这行代码
        field.set(obj, value);
    }
    public static Table getTableAnnotation(Object obj) {
        return obj.getClass().getAnnotation(Table.class);
    }
}
